package com.jf3q.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jf3q.admin.service.impl.MemberServiceImpl;
import com.jf3q.admin.utils.vo.AjaxResultVO;
import com.jf3q.common.domain.EduMember;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

/**
 * @author ASUS
 * @date 2024/6/3
 * @apiNote
 */
@RestController
@RequestMapping("/member")
public class MemberController {

    @Autowired
    MemberServiceImpl memberService;

    @PostMapping("/page")
    public AjaxResultVO page(@RequestBody EduMember member,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = ""+Integer.MAX_VALUE) Integer pageSize){
        LambdaQueryWrapper<EduMember> memberWrapper=new LambdaQueryWrapper<>();
        if (!ObjectUtils.isEmpty(member)){
            if (!ObjectUtils.isEmpty(member.getNickname())){
                memberWrapper.like(EduMember::getNickname, member.getNickname());
            }
            if (!ObjectUtils.isEmpty(member.getMobile())){
                memberWrapper.eq(EduMember::getMobile,member.getMobile());
            }
            memberWrapper.orderByDesc(EduMember::getEduModified);
        }
        Page<EduMember> page=memberService.page(new Page<>(pageNum,pageSize),memberWrapper);
        return AjaxResultVO.success(page);
    }

    @PostMapping("/disabled")
    public AjaxResultVO delete(@RequestBody EduMember member){
        boolean b = memberService.updateById(member);
        return b?AjaxResultVO.success():AjaxResultVO.error();
    }
}
